home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / headers / fileclass.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.8 KB  |  174 lines

  1. /*
  2.     File:        FileClass.h
  3.  
  4.     Contains:    TFile is a simple object that does file manipulations    
  5.                   TFile.h contains the TFile class and subclass definitions. 
  6.  
  7.     Written by: Kent Sandvik    
  8.  
  9.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24. // Declare label for this header file
  25. #ifndef _FILECLASS_
  26. #define _FILECLASS_
  27.  
  28. #ifndef _DTSCPLUSLIBRARY_
  29. #include "DTSCPlusLibrary.h"
  30. #endif
  31.  
  32. #ifndef __FILES__
  33. #include <Files.h>
  34. #endif
  35.  
  36. #ifndef __OSUTILS__
  37. #include <OSUtils.h>
  38. #endif
  39.  
  40. #ifndef __RESOURCES__
  41. #include <Resources.h>
  42. #endif
  43.  
  44. // globals
  45. const OSType kDefaultCreator = '????';
  46. const OSType kDefaultType = 'TEXT';
  47. const SignedByte kExclusiveReadWrite = 0;
  48. const long kNoOffset = 0L;
  49.  
  50. // _________________________________________________________________________________________________________ //
  51. //    TFile Class Interface.
  52. class TFile
  53. // Basic File class for file I/O handling.
  54. {
  55. public:
  56.     // CONSTRUCTORS AND DESTRUCTORS
  57.     TFile(char* name = "UnTitled");                    // define file based on name (current folder)
  58.     TFile(FSSpec theSpec);                            // define file based on FSSpec
  59.     TFile(short volume,                                // define file based on volume, dirID and name (FSSpec)
  60.           long dirID,
  61.           Str63 name);
  62.  
  63.     virtual~ TFile();                                // default destructor                        
  64.  
  65.     virtual void Initialize();                        // initialize fields to known values
  66.  
  67.     // MAIN INTERFACE
  68.     virtual Boolean Create();                        // create a file
  69.     virtual Boolean Rename(char* newName);            // rename the file
  70.     virtual void Delete();                            // delete the file
  71.     virtual Boolean FileExists();                    // check if file exists
  72.     virtual Boolean Open(SignedByte permission) = 0;// open file
  73.     virtual Boolean Close() = 0;                    // close file
  74.  
  75.     // ACCESSORS AND MUTATORS
  76.     virtual void SetType(const OSType creator,        // define file type and creator
  77.                          const OSType fileType);
  78.     virtual void SetFileName(const Str63 fileName);    // set name of file
  79.     virtual FInfo GetFileInfo();                    // get file information frome the specific file
  80.  
  81.     // FIELDS
  82. protected:
  83.     FSSpec fFileSpec;                                // the generic container for File information
  84.     OSType fFileType;                                // type of file
  85.     OSType fCreator;                                // creator of file
  86.     Boolean fOpened;                                // keep track if the file is open or not
  87.     Boolean fFlushing;                                // should we flush after each file operation?
  88.     short fRefNum;                                    // reference number to the file
  89.     OSErr fError;                                    // latest error
  90. };
  91.  
  92.  
  93. // _________________________________________________________________________________________________________ //
  94. //    TDataFile Class Interface.
  95. class TDataFile : public TFile
  96. // TData file is a file that uses mainly the data fork of the file.
  97. {
  98. public:
  99.     // CONSTRUCTORS AND DESTRUCTORS
  100.     TDataFile(char* name = "UnTitled");                // default constructor
  101.     ~TDataFile();                                    // default destructor
  102.  
  103.     // MAIN INTERFACE
  104.     virtual Boolean Open(SignedByte permission = kExclusiveReadWrite);// exclusive read/write permission
  105.     virtual Boolean Close();                        // close the file
  106.     virtual Boolean WriteHandle(Handle h);            // write handle into disk
  107.     virtual Handle ReadHandle();                    // read handle from disk
  108.     virtual Boolean Write(Ptr buffer,
  109.                           long bytes);                // write bytes to disk from current mark
  110.     virtual Boolean Read(Ptr buffer,
  111.                          long bytes);                // read bytes from disk at current mark
  112.     virtual Boolean SetMark(short from,
  113.                             long offset);            // set offset of mark
  114.     virtual long GetMark();                            // get offset
  115.     virtual Boolean Reset();                        // set file mark to beginning of file
  116.     virtual Boolean GotoEndOfFile();                // set file mark at end of file 
  117. };
  118.  
  119. // _________________________________________________________________________________________________________ //
  120. //    TResourceFile Class Interface.
  121. class TResourceFile : public TFile
  122. // TResourceFile uses mainly the resource fork of the file.
  123. {
  124. public:
  125.     // CONSTRUCTORS AND DESTRUCTORS
  126.     TResourceFile(char* name = "UnTitled");            // default constructor
  127.     ~TResourceFile();                                // default destructor
  128.  
  129.     // MAIN INTERFACE
  130.     virtual Boolean Create();                        // create a file
  131.     virtual Boolean Open(SignedByte permission = kExclusiveReadWrite);    // open the file
  132.     virtual Boolean Close();                        // close the file
  133.  
  134.     virtual Boolean HasResourceFork();                // test if file has resource fork or not
  135.     virtual void Update();                            // update the file
  136.     virtual void Assign();                            // assign the file to the first one in the resource chain
  137. };
  138.  
  139.  
  140. // _________________________________________________________________________________________________________ //
  141. //    MPreferences Class Interface.
  142. class MPreferences
  143. // Find and create files in the preferences section of the hard disk (future)
  144. {
  145. public:
  146. };
  147.  
  148.  
  149. // _________________________________________________________________________________________________________ //
  150. //    MTempFile Class Interface.
  151. class MTempFile
  152. // Find and create files in the temp section of the hard disk (future)
  153. {
  154. public:
  155. };
  156.  
  157.  
  158. // _________________________________________________________________________________________________________ //
  159. //    TLogFile Class Interface.  (future)
  160. class TLogFile : public TFile
  161. {
  162. public:
  163. };
  164.  
  165.  
  166. #endif
  167.  
  168. // _________________________________________________________________________________________________________ //
  169. /*    Change History (most recent last):
  170.   No        Init.    Date        Comment
  171.   1            khs        12/27/92    New file
  172.   2            khs        1/14/93        Cleanup
  173. */
  174.